package com.yanqu.road.server.cmd.match;

import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.match.MatchModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/2/6 18:02
 */
@Cmd(code = GameProtocol.S_VARIETY_DISPATCH_TEAM, desc = "派遣队伍")
public class DispatchTeamCmd extends AbstractCommand {
    private int id; //杂艺id
    private int level;  //杂艺等级
    private int occupation; //杂艺职业类型
    private int matchId; //杂艺id
    private List<Integer> patronsIdList; //派遣门客列表

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VarietyProto.DispatchTeamReqMsg msg = VarietyProto.DispatchTeamReqMsg.parseFrom(packet.getBytes());
        id = msg.getId();
        level = msg.getLevel();
        occupation = msg.getOccapution();
        patronsIdList = msg.getPatronsIdList();
        matchId = msg.getVarietyId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(MatchModule.class).dispatchTeam(id, level, occupation, matchId, patronsIdList);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            VarietyProto.DispatchTeamRespMsg.Builder respMsg = VarietyProto.DispatchTeamRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_VARIETY_DISPATCH_TEAM, respMsg);
        }
    }
}
